﻿using System;
using System.Reflection;
using System.Runtime.Serialization;
using Cubicle.Core.Shared;

namespace Cubicle.Core.DataContracts
{
    [DataContract]
    [Serializable]
    public class MethodData
    {

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public int Offset { get; set; }

        [DataMember]
        public string ReturnType { get; set; }

        [DataMember]
        public int ParameterCount { get; set; }

        [DataMember]
        public string Help { get; set; }

        [DataMember]
        public bool IsGenericMethod { get; set; }

        [DataMember]
        public string DeclaringType { get; set; }

        [DataMember]
        public bool IsAssembly { get; set; }

        [DataMember]
        public bool IsFamily { get; set; }

        [DataMember]
        public bool IsFamilyAndAssembly { get; set; }

        [DataMember]
        public bool IsFinal { get; set; }

        [DataMember]
        public bool IsPrivate { get; set; }

        [DataMember]
        public bool IsStatic { get; set; }

        [DataMember]
        public bool IsVirtual { get; set; }

        public MethodData(MethodInfo m, int offset = 0)
        {
            Name = m.Name;
            Offset = offset;
            ReturnType = m.ReturnType.FullName ?? m.ReflectedType.Name;
            Help = m.Help();
            ParameterCount = m.GetParameters().Length;
            DeclaringType = m.DeclaringType.FullName ?? m.DeclaringType.Name;
            IsGenericMethod= m.IsGenericMethod;
            IsAssembly= m.IsAssembly;
            IsFamily= m.IsFamily;
            IsFamilyAndAssembly= m.IsFamilyAndAssembly;
            IsFinal= m.IsFinal;
            IsPrivate= m.IsPrivate;
            IsStatic= m.IsStatic;
            IsVirtual = m.IsVirtual;
        }

    }
}